use std::thread::sleep;
use std::time::Duration;
use serde::Serialize;
use tokio::select;
use lipo_base::log_error;
use crate::lbean::ResultData;

pub(crate) mod lmqtt;
pub(crate) mod lhttp;
pub(crate) mod ldb;
pub(crate) mod lbean;
pub(crate) mod lservice;


#[macro_export]
macro_rules! result_for_error {
    ($code:expr,$msg:expr) => (
        crate::lbean::ResultData::<String>::result_error($code, $msg);
    );
}

#[macro_export]
macro_rules! result_for_success {
    ($data:expr) => {
        crate::lbean::ResultData::result_success($data)
    };
}

#[tokio::main]
async fn main() {
    // test_main().await;

    lhttp::start_http_server().await

    ////////////////////////////////////////////////////////////////
    // let mqtt_handle = tokio::spawn(async {
    //     lmqtt::start_mqtt_server().await
    // });
    // let http_handle = tokio::spawn(async {
    //     lhttp::start_http_server().await
    // });
    //
    // select! {
    //      _ = mqtt_handle => {
    //         log_error!("mqtt 系统服务终止了")
    //     },
    //      _ =  http_handle => {
    //         log_error!("http 系统服务终止了")
    //     },
    // }
}

#[derive(Serialize, Debug, Clone)]
struct TData {
    name: String,
    age: u8,
    like: Vec<String>,
}

#[derive(Serialize, Debug, Clone)]
struct TData2 {
    name: String,
    td: TData,
}

async fn test_main() {
    let re1 = ResultData::<String>::result_error(100, "失败了吧".to_string());
    println!("打印输出errror: {}", re1);

    let td = TData {
        name: "小柳".to_string(),
        age: 26,
        like: vec!["语文".to_string(), "数学".to_string()],
    };

    let td2 = TData2{
        name: "生机".to_string(),
        td
    };

    let re2 = ResultData::<Vec<String>>::result_success(vec![]);
    println!("success: {}", re2);
}
